package com.link2room.optimus.controller.manager;

import com.link2room.common.constant.BaseConstant;
import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.jpa.result.QueryResult;
import com.link2room.optimus.dto.param.manager.MarketingManagerParamDto;
import com.link2room.optimus.facade.IMarketingFacadeService;
import com.link2room.optimus.dto.result.base.*;
import com.link2room.sideswipe.permissionResouces.annotation.L2RPermissionResources;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

import static com.link2room.optimus.constant.PermissionConstant.*;

/**
 * Created by sss on 2016/9/2.
 */
@Api(tags = "活动商品管理")
@RestController
@RequestMapping("/manager/Marketings")
public class MarketingManagerController {
    @Resource
    private IMarketingFacadeService marketingFacadeService;

    @ApiOperation(value = "新建活动商品基础信息",response = MarketingDto.class)
    @RequestMapping(method = RequestMethod.POST)
    @L2RPermissionResources(value = newMarketing, name = "新建活动")
    public BaseResultDto newMarketing(
            @RequestBody MarketingManagerParamDto marketingManagerParamDto
    ) throws Exception {
        MarketingDto marketingDto = marketingFacadeService.saveMarketing(marketingManagerParamDto);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(marketingDto);
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.SAVESUCCESS);
        return l2rRs;
    }

    @ApiOperation(value = "获取活动列表",response = MarketingDto.class)
    @RequestMapping(method = RequestMethod.GET)
    @L2RPermissionResources(value = marketings,name = "获取活动列表")
    public BaseResultDto marketings() throws Exception {
        MarketingManagerParamDto marketingManagerParamDto=new MarketingManagerParamDto();
        QueryResult<MarketingDto> marketingResult = marketingFacadeService.listMarketings(marketingManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(marketingResult);
        return l2rRs;
    }

    @ApiOperation(value = "根据ID获取活动",response = MarketingDto.class)
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    @L2RPermissionResources(value = marketingById, name = "活动详情ById")
    public BaseResultDto marketing(
            @PathVariable Long id
    ) throws Exception {
        MarketingManagerParamDto marketingManagerParamDto=new MarketingManagerParamDto();
        marketingManagerParamDto.setId(id);
        MarketingDto marketing = marketingFacadeService.findMarketing(marketingManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(marketing);
        return l2rRs;
    }

    @ApiOperation(value = "根据mcCode获取活动所有信息",response = MarketingAllDto.class)
    @RequestMapping(value = "/Marketing",method = RequestMethod.GET)
    public BaseResultDto marketingAll(
            @RequestParam(value = "mcCode", required = true) String mcCode
    ) throws Exception {
        MarketingManagerParamDto marketingManagerParamDto = new MarketingManagerParamDto();
        marketingManagerParamDto.setMcCode(mcCode);
        MarketingAllDto marketingAll = marketingFacadeService.findMarketingAll(marketingManagerParamDto);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(marketingAll);
        return l2rRs;
    }

    @ApiOperation(value = "活动代码校验")
    @RequestMapping(value = "/McCode",method = RequestMethod.GET)
    public BaseResultDto mcCode(
            @RequestParam(value = "mcCode" ,required = true) String mcCode
    ) throws Exception {
        MarketingManagerParamDto marketingManagerParamDto=new MarketingManagerParamDto();
        marketingManagerParamDto.setMcCode(mcCode);
        marketingFacadeService.checkMcCode(marketingManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        return l2rRs;
    }

    @ApiOperation(value = "更新活动基础信息")
    @RequestMapping(method = RequestMethod.PUT)
    @L2RPermissionResources(value = updateMarketing, name = "活动更新")
    public BaseResultDto updateMarketing(
            @RequestBody MarketingManagerParamDto marketingManagerParamDto
    ) throws Exception {
        marketingFacadeService.updateMarketing(marketingManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.SAVESUCCESS);
        return l2rRs;
    }

    @ApiOperation(value = "保存活动酒店信息",response = MarketingHotelDto.class)
    @RequestMapping(value = "/MarketingHotels",method = RequestMethod.POST)
    @L2RPermissionResources(value = newMarketingHotel, name = "新建活动酒店")
    public BaseResultDto newMarketingHotels(
            @RequestBody MarketingManagerParamDto marketingManagerParamDto
    ) throws Exception {
        List<MarketingHotelDto> marketingHotels = marketingFacadeService.saveMarketingHotels(marketingManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(marketingHotels);
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.SAVESUCCESS);
        return l2rRs;
    }

    @RequestMapping(value = "/MarketingHotels", method = RequestMethod.GET)
    @L2RPermissionResources(value = marketingHotels, name = "活动酒店列表")
    @ApiOperation(value = "获取活动酒店列表",response = MarketingHotelDto.class)
    public BaseResultDto marketingHotels(
            @RequestParam(value = "mcCode" ,required = true) String mcCode
    ) throws Exception {
        MarketingManagerParamDto marketingManagerParamDto=new MarketingManagerParamDto();
        marketingManagerParamDto.setMcCode(mcCode);
        QueryResult<MarketingHotelDto> marketingHotelResult = marketingFacadeService.listMarketingHotels(marketingManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(marketingHotelResult);
        return l2rRs;
    }

    @ApiOperation(value = "更新活动酒店列表",response = MarketingHotelDto.class)
    @RequestMapping(value = "/MarketingHotels",method = RequestMethod.PUT)
    @L2RPermissionResources(value = updateMarketingHotels, name = "更新活动酒店")
    public BaseResultDto updateMarketingHotels(
            @RequestBody MarketingManagerParamDto marketingManagerParamDto
    ) throws Exception {
        List<MarketingHotelDto> marketingHotels =marketingFacadeService.updateMarketingHotels(marketingManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(marketingHotels);
        return l2rRs;
    }

    @ApiOperation(value = "保存活动房型信息",response = MarketingRmtypeDto.class)
    @RequestMapping(value = "/MarketingRmtypes",method = RequestMethod.POST)
    @L2RPermissionResources(value = newMarketingRmtypes, name = "新建活动房型")
    public BaseResultDto newMarketingRmtypes(
            @RequestBody MarketingManagerParamDto marketingManagerParamDto
    ) throws Exception {
        List<MarketingRmtypeDto> marketingRmtypeDtos = marketingFacadeService.saveMarketingRmtypes(marketingManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(marketingRmtypeDtos);
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.SAVESUCCESS);
        return l2rRs;
    }

    @ApiOperation(value = "更新活动房型信息")
    @RequestMapping(value = "/MarketingRmtypes",method = RequestMethod.PUT)
    @L2RPermissionResources(value = updateMarketingRmtypes, name = "更新活动房型")
    public BaseResultDto updateMarketingRmtypes(
            @RequestBody MarketingManagerParamDto marketingManagerParamDto
    ) throws Exception {
        marketingFacadeService.updateMarketingRmtypes(marketingManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.UPDATESUCCESS);
        return l2rRs;
    }

    @ApiOperation(value = "获取活动房型列表",response = MarketingRmtypeDto.class)
    @RequestMapping(value = "/MarketingRmtypes",method = RequestMethod.GET)
    @L2RPermissionResources(value = marketingRmtypes, name = "活动房型列表")
    public BaseResultDto marketingRmtypes(
            @RequestParam(value = "mcCode" ,required = true) String mcCode
    ) throws Exception {
        MarketingManagerParamDto marketingManagerParamDto=new MarketingManagerParamDto();
        marketingManagerParamDto.setMcCode(mcCode);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(marketingFacadeService.listMarketingRmtypes(marketingManagerParamDto));
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.SAVESUCCESS);
        return l2rRs;
    }

    @ApiOperation(value = "保存活动渠道信息",response = MarketingPbChannelDto.class)
    @RequestMapping(value = "/MarketingPbChannels",method = RequestMethod.POST)
    @L2RPermissionResources(value = newMarketingPbChannels, name = "新建活动渠道")
    public BaseResultDto newMarketingPbChannels(
            @RequestBody MarketingManagerParamDto marketingManagerParamDto
    ) throws Exception {
        List<MarketingPbChannelDto> marketingPbChannelDtos = marketingFacadeService.saveOrUpdateMarketingPbChannels(marketingManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(marketingPbChannelDtos);
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.SAVESUCCESS);
        return l2rRs;
    }

    @ApiOperation(value = "获取活动渠道信息",response = MarketingPbChannelDto.class)
    @RequestMapping(value = "/MarketingPbChannels",method = RequestMethod.GET)
    @L2RPermissionResources(value = marketingPbChannels, name = "活动渠道列表")
    public BaseResultDto marketingPbChannels(
            @RequestParam(value = "mcCode" ,required = true) String mcCode
    ) throws Exception {
        MarketingManagerParamDto marketingManagerParamDto=new MarketingManagerParamDto();
        marketingManagerParamDto.setMcCode(mcCode);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(marketingFacadeService.listMarketingPbChannels(marketingManagerParamDto));
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.SAVESUCCESS);
        return l2rRs;
    }

    @ApiOperation(value = "更新活动渠道信息",response = MarketingPbChannelDto.class)
    @RequestMapping(value = "/MarketingPbChannels",method = RequestMethod.PUT)
    @L2RPermissionResources(value = updateMarketingPbChannels, name = "更新活动渠道")
    public BaseResultDto updateMarketingPbChannels(
            @RequestBody MarketingManagerParamDto marketingManagerParamDto
    ) throws Exception {
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.SAVESUCCESS);
        l2rRs.setListToQueryResult(marketingFacadeService.saveOrUpdateMarketingPbChannels(marketingManagerParamDto));
        return l2rRs;
    }

    @ApiOperation(value = "保存活动明细")
    @L2RPermissionResources(value = newMarketingDetails, name = "新建活动详情")
    public BaseResultDto newMarketingDetails(
            @RequestBody MarketingManagerParamDto marketingManagerParamDto
    ) throws Exception {
        marketingFacadeService.saveMarketingDetail(marketingManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.SAVESUCCESS);
        return l2rRs;
    }

    @ApiOperation(value = "更新活动明细")
    @L2RPermissionResources(value = updateMarketingDetails, name = "更新活动详情")
    @RequestMapping(value = "/MarketingDetails",method = RequestMethod.PUT)
    public BaseResultDto updateMarketingDetails(
            @RequestBody MarketingManagerParamDto marketingManagerParamDto
    ) throws Exception {
        marketingFacadeService.updateMarketingDetail(marketingManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.SAVESUCCESS);
        return l2rRs;
    }

    @ApiOperation(value = "获取活动明细",response = MarketingDetailDto.class)
    @RequestMapping(value = "/MarketingDetails",method= RequestMethod.GET)
    @L2RPermissionResources(value = marketingDetails, name = "活动详情列表")
    public BaseResultDto marketingDetails(
            @RequestParam(value = "lhotelCode" ,required = false) String lhotelCode,
            @RequestParam(value = "mcCode" ,required = true) String mcCode,
            @RequestParam(value = "currentPage" ,required = false) Integer currentPage,
            @RequestParam(value = "pageSize" ,required = false) Integer pageSize
    ) throws Exception {
        MarketingManagerParamDto marketingManagerParamDto=new MarketingManagerParamDto();
        marketingManagerParamDto.setLhotelCode(lhotelCode);
        marketingManagerParamDto.setMcCode(mcCode);
        marketingManagerParamDto.setCurrentPage(currentPage);
        marketingManagerParamDto.setPageSize(pageSize);
        QueryResult<MarketingDetailDto> marketingDetailDtoQueryResult=marketingFacadeService.listMarketingDetails(marketingManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(marketingDetailDtoQueryResult);
        return l2rRs;
    }

    @ApiOperation(value = "获取酒店参加活动列表",response = MarketingDto.class)
    @RequestMapping(value = "/HotelEnterMarketings",method = RequestMethod.GET)
    public BaseResultDto rmtypeEnterMarketings(
            @RequestParam(value = "lhotelCode" ,required = true) String lhotelCode
    ) throws Exception {
        MarketingManagerParamDto marketingManagerParamDto=new MarketingManagerParamDto();
        marketingManagerParamDto.setLhotelCode(lhotelCode);
        QueryResult<MarketingDto> marketingResult = marketingFacadeService.listHotelEnterMarketings(marketingManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(marketingResult);
        return l2rRs;
    }

    @ApiOperation(value = "保存酒店参加活动列表")
    @RequestMapping(value = "/HotelEnterMarketings",method = RequestMethod.POST)
    @L2RPermissionResources(value = newHotelEnterMarketingDetail, name = "活动添加酒店")
    public BaseResultDto newHotelEnterMarketingDetail(
            @RequestBody MarketingManagerParamDto marketingManagerParamDto
    ) throws Exception {
        marketingFacadeService.saveOrUpdateHotelEnterMarketingDetail(marketingManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.SAVESUCCESS);
        return l2rRs;
    }

    @RequestMapping(value = "/RmtypeEnterMarketings",method = RequestMethod.GET)
    public BaseResultDto rmtypeEnterMarketings(
            @RequestParam(value = "lhotelCode" ,required = true) String lhotelCode,
            @RequestParam(value = "rmtype" ,required = true) String rmtype,
            @RequestParam(value = "groupRmtype" ,required = true) String groupRmtype
    ) throws Exception {
        MarketingManagerParamDto marketingManagerParamDto=new MarketingManagerParamDto();
        marketingManagerParamDto.setLhotelCode(lhotelCode);
        marketingManagerParamDto.setRmtype(rmtype);
        marketingManagerParamDto.setGroupRmtype(groupRmtype);
        QueryResult<MarketingDto> marketingResult = marketingFacadeService.listRmtypeEnterMarketings(marketingManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(marketingResult);
        return l2rRs;
    }

    @ApiOperation(value = "保存房型参加活动列表")
    @RequestMapping(value = "/RmtypeEnterMarketingDetails",method = RequestMethod.POST)
    @L2RPermissionResources(value = newRmtypeEnterMarketingDetail, name = "活动添加房型")
    public BaseResultDto newRmtypeEnterMarketingDetail(
            @RequestBody MarketingManagerParamDto marketingManagerParamDto
    ) throws Exception {
        marketingFacadeService.saveOrUpdateRmtypeEnterMarketingDetail(marketingManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultMessage(BaseConstant.BaseMessageConstant.SAVESUCCESS);
        return l2rRs;
    }
}
